home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / multi-4a / about.txt next >
Text File  |  1999-08-14  |  3KB  |  55 lines

  1. Hi, i've had 3 requests/moans recently from friends who want to learn how to make 
  2. multi-client server applications. well, all server applications have the same mainframe. 
  3.  
  4. so i have written some nice code for a very efficent mainframe for a multi-client chat server.
  5.  
  6. i have written lots and lots of comments into the code, so it should all be pretty straight forward.
  7.  
  8. Please note, if your going to be using my source-code in you project then please give me some credit for it.
  9.  
  10.                         - Pirotic
  11.  
  12.  
  13. Extra Info
  14. ==========
  15. just remembered all my friends are idiots so you'll probably need a better explanation of how it works... so here we are.
  16.  
  17. the way a server works is complex so bare with me.
  18.  
  19. all the users connect on the same port, such as 6667. now most people wonder
  20. how on earth you get more than 1 connection on a port. well, you can't.
  21.  
  22. you can however transfere the connection request to another port. which can
  23. then accept the connection.
  24.  
  25. so what i have done is create an array of socks (winsock), now. the first
  26. sock in this array, sock(0), is the main one which everybody connects to.
  27. so i set the local port as the server_port (in the settings.bas) and set
  28. it to listen for connections.
  29.  
  30. now when it get a connection request it looks though all the other socks in its array.
  31. at first their wont be any more (as it saves memory). but what it does is it checks if there is an un-used socket, is their is it'll connect them on that, but if their are no sockets left.(and the maximum number of clients hasn't been met) then it'll create a new socket in the array to accomidate the new user.
  32.  
  33. now, we need to store infomation of all the clients. 
  34.  
  35. so i created a new array called clients, their is 1 for each possible client (it uses the max_clients value in the settings.bas)
  36.  
  37. in here i have only included the basic variables, such as socket (this is the array nunber of the socket they are connected to), time connected and idle_time. obviously
  38. you add your own values for the type of server your are doing. this information is
  39. the client-information. and the number of the array they are using is called the ClientID.
  40.  
  41. so when somebody connects not only does it find them a port. but it also finds a clientID that isnt in use (as its either unused, or its previous user has disconnected)
  42.  
  43. so once a client connects they'll be given a clientID and a socket. now for the engine to work you need to be able to find out one from the other. so the socket information is kept in the client_information part. as 'socket' (which is a interger). and the tag
  44. of the socket they are using is set to the ClientID. 
  45.  
  46. All things such as server-full messages have been done. and whenever a user disconnects it automatically blanks all the infomation so it can be used again.
  47.  
  48. so all whats left to do is ADD (not change) new code to suite your server.
  49.  
  50. erm.. read the source code. that explains it all quite well. if you still ned help
  51. then mail me at :
  52.  
  53.               Pirotic@hotmail.com
  54.  
  55. hope this helped.